<template>
    <Modal title="设置分类" @on-visible-change="showModal" v-model="show" :closable="false" :mask-closable="false">
        <el-form ref="back" label-position="right" label-width="80px">
            <el-select size="small" v-model="categoryId" placeholder="请选择">
                <el-option v-for="item in categorys" :key="item.id" :label="item.name" :value="item.id">
                </el-option>
            </el-select>
            <el-button size="small" icon="el-icon-refresh" @click="getWarehouses" :loading="loadingWarehouse"></el-button>
        </el-form>
        <div slot="footer">
            <el-button size="small" @click="cancel">取消</el-button>
            <el-button @click="ok" type="success" size="small" :loading="loading">确认设置</el-button>
        </div>
    </Modal>
</template>
<script>
export default {
    name: "CXiapiCost",
    data() {
        return {
            loading: false,
            loadingWarehouse: false,
            categorys: [],
            categoryId: null,
            ids: null,
            show: false,
        }
    },
    props: [

    ],
    methods: {
        showModal: function(val) {
            if (val) {
                this.getWarehouses();
            } else {
                this.categoryId = null;
                this.categorys = [];
            }
        },
        showDialog: function(ids) {
            this.ids = ids;
            this.show = true;
        },
        submit: function() {
            var me = this;
            // if (this.categorys.length <= 0) {
            //     this.errorMessage("请先选择仓库");
            //     return false;
            // }
            me.loading = true;
            me.$http.post("/storageproduct/batchCategory.do", { categoryId: me.categoryId, ids: me.ids }).then(response => {
                me.loading = false;

                var body = response;
                if (body.status == 0) {
                    me.$emit('ok');
                    me.show = false;
                    me.successMessage("设置成功！");
                } else {
                    me.errorMessage(body.info);
                }

            }, response => {
                me.loading = false;
            });
        },
        getWarehouses: function() {
            var me = this;
            me.loadingWarehouse = true;

            me.$http.post("/storageproductcategory/list.do", {}).then(response => {
                me.loadingWarehouse = false;
                var body = response;
                if (body.status == 0) {

                    me.categorys = body.obj;

                } else {
                    me.errorMessage(body.info);
                }

            }, response => {
                me.loadingWarehouse = false;
            });
        },
        ok: function() {
            this.submit();
        },
        cancel: function() {
            this.show = false;
            this.$emit('cancel')
        }

    }
}
</script>
<style scoped>
.ivu-alert-with-desc {
    padding: 0px 16px;
}

.time {
    font-size: 14px;
    font-weight: bold;
}

.content {
    padding-left: 5px;
    word-wrap: break-word;
}
</style>